package mf.com.controller.product;

import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.annotation.Resource;
import jakarta.servlet.http.HttpServletResponse;
import mf.com.Service.Product.CategoryService;
import mf.com.entity.product.Category;
import mf.com.vo.common.Result;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import java.util.List;

/**
 * @Author: lmf
 * @Create: 2024/3/31 16:16
 * Description:  分类控制层
 */
@RestController
@Tag(name = "分类管理")
@RequestMapping(value = "/admin/product/category")
public class CategoryController {
    @Resource
    private CategoryService categoryService;

    @GetMapping("/findCategoryList/{id}")
    @Operation(summary = "查询第一层菜单")
    public Result<List<Category>> findCategoryList(@PathVariable("id") Long id) {
       return Result.success(categoryService.findById(id));
    }

    @GetMapping("/exportData")
    @Operation(summary = "导出")
    public void exportData(HttpServletResponse response) {
      categoryService.exportData(response);
    }

    @PostMapping("/importData")
    @Operation(summary = "导入")
    public Result<Void> importData(MultipartFile file) {
        // 获取上传文件
        categoryService.importData(file);
        return Result.success(null);
    }


}
